home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / os2 / cenvi2.arj / FRANTICK.CMM < prev    next >
Text File  |  1993-07-15  |  1KB  |  40 lines

  1. // Frantick.cmm - silly CEnvi program to bounce an asterisk around the screen
  2.  
  3. // find out how big the screen is
  4. MaxRow = ScreenSize().row - 1;
  5. MaxCol = ScreenSize().col - 1;
  6.  
  7. // get a random initial position for the bouncy asterisk
  8. srand();
  9. OldRow = rand() % (MaxRow + 1);
  10. OldCol = rand() % (MaxCol + 1);
  11.  
  12. // clear the screen to start with a fesh slate
  13. ScreenClear();
  14.  
  15. while ( !kbhit() ) {
  16.    // draw new dots and erase old ones forever
  17.    do {
  18.       // calculate new row, so long as it is in bounds
  19.       Row = OldRow + (rand() % 3) - 1;
  20.    } while( Row < 0  ||  MaxRow < Row );
  21.    do {
  22.       // calculate new column, so long as it is in bounds
  23.       Col = OldCol + (rand() % 3) - 1;
  24.    } while( Col < 0  ||  MaxCol < Col );
  25.    SafePutchar(' ',OldRow,OldCol);
  26.    SafePutchar('*',OldRow = Row,OldCol = Col);
  27. }
  28.  
  29. SafePutchar(c,row,col) // just like putchar, but won't write into lower-right corner
  30. {                      // so we don't get accidental scrolling
  31.    ScreenCursor(col,row);
  32.    if ( row != MaxRow  ||  col != MaxCol ) {
  33.       putchar(c);
  34.    }
  35.    ScreenCursor(col,row);
  36. }
  37.  
  38. // flush the keyboard
  39. while( kbhit() ) getch();
  40.